package com.glsc.ngateway.common.api.flowable.feign;

import com.glsc.ngateway.common.api.common.config.FeignMultipartSupportConfig;
import com.glsc.ngateway.common.api.common.dto.PageDataResult;
import com.glsc.ngateway.common.api.flowable.dto.FlowableCopyDto;
import com.glsc.ngateway.common.api.flowable.dto.ForwardFlowableParamDto;
import com.glsc.ngateway.common.api.flowable.dto.TaskDefinitionDto;
import com.glsc.ngateway.common.api.flowable.dto.demand.FlowableAppendDto;
import com.glsc.ngateway.common.api.flowable.dto.demand.FlowableAssigneeDto;
import com.glsc.ngateway.common.api.flowable.dto.demand.FlowableDemandDto;
import com.glsc.ngateway.common.api.flowable.dto.demand.FlowableEhrEmpDto;
import com.glsc.ngateway.common.api.flowable.dto.param.*;
import com.glsc.ngateway.common.api.flowable.resp.*;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@FeignClient(value = "EUREKA-CLIENT-FLOWABLE", configuration = FeignMultipartSupportConfig.class) // 调用的服务的名称
public interface IFeignFlowableService {

    @PostMapping(value = "/flowable/common/oaDownloadAppendix/{appendixId}")
    ResponseEntity<byte[]> oaDownloadAppendix(@PathVariable("appendixId") String appendixId);
    /**
     * 创建流程
     */
    @PostMapping("/flowable/process/create")
    FlowableResponse<ResponseCreateDto> create(@RequestBody ParamCreateDto paramCreateDto);

    /**
     * 查看流程实例历史明细
     */
    @PostMapping("/flowable/process/hisDetailList")
    FlowableResponse<PageDataResult<ResponseDetailDto>> hisDetailList(@RequestParam(value = "pageNum") Integer pageNum,
                                                                      @RequestParam(value = "pageSize") Integer pageSize, @RequestBody ParamHisdetailDto params);


    /**
     * 批准
     * <p>
     * taskId
     * content
     * sysid
     * comment
     */
    @PostMapping("/flowable/process/doTask")
    FlowableResponse<ResponseMsgDto> doTask(@RequestBody ParamDoTaskDto paramDotaskDto);

    /**
     * 回退驳回
     * <p>
     * taskId
     * content
     * sysid
     * comment
     */
    @PostMapping("/flowable/process/rollback")
    FlowableResponse<ResponseMsgDto> rollback(@RequestBody ParamRollbackDto paramRollbackDto);


    /**
     * 待办
     * 查询当前节点的父节点表单内容
     */
    @ResponseBody
    @RequestMapping(value = "/flowable/process/queryParentFormData")
    String queryParentFormData(@RequestParam("taskId") String taskId);


    /**
     * 入口：发起的流程 已办的流程 办结的流程
     * 查询当前流程最新节点的父节点表单内容
     */
    @ResponseBody
    @RequestMapping(value = "/flowable/process/queryLatestFormData")
    String queryLatestFormData(@RequestParam("processId") String processId);

    /**
     * 中止流程
     */
    @GetMapping("/flowable/process/stop")
    FlowableResponse<ResponseMsgDto> stopProcessInstanceById(@RequestParam("processId") String processId, @RequestParam("operator") String operator);

    /**
     * 查看流程实例是否结束
     * true 结束
     */
    @GetMapping(value = "/flowable/process/checkProcessEnd")
    boolean checkProcessEnd(@RequestParam("processId") String processId);

    /**
     * 生成流程图 正在用
     *
     * @param processId 任务ID
     */
    @RequestMapping("/flowable/process/processDiagram")
    @ResponseBody
    void genProcessDiagram(@RequestParam("httpServletResponse") HttpServletResponse httpServletResponse, @RequestParam("processId") String processId) throws Exception;


    /**
     * 获取该task相关信息
     */
    @RequestMapping(value = "/flowable/process/getTaskInfo")
    FlowableResponse<ResponseSituationDto> getTaskInfo(@RequestParam("taskId") String taskId, @RequestParam("sysid") String sysid);

    /**
     * 获取该流程评注意见
     */
    @RequestMapping(value = "/flowable/process/queryCommentsByProcessId")
    FlowableResponse<PageDataResult<ResponseCommentDto>> queryCommentsByProcessId
    (@RequestParam(value = "pageNum") Integer pageNum,
     @RequestParam(value = "pageSize") Integer pageSize,
     @RequestBody ParamCommentDto params);

//    /**
//     * 生成流程图 正在用 接口形式
//     *
//     * @param processId 任务ID
//     */
//    @RequestMapping(method = RequestMethod.GET, value = "/flowable/process/processDiagramStream/{processId}")
//    public Response processDiagramStream(@RequestParam("processId") String processId) throws Exception;

    /**
     * 从网关下载工作流进展图
     *
     * @param processId 流程ID
     * @return
     */
    @RequestMapping(method = RequestMethod.GET, value = "/flowable/process/processDiagramStream")
    ResponseEntity<byte[]> processDiagramStream(@RequestParam("processId") String processId);


    @RequestMapping(method = RequestMethod.POST, value = "/flowable/process/copyProcess")
    @ApiOperation(value = "抄送流程", notes = "抄送流程")
    FlowableResponse<ResponseMsgDto> copyProcess(@RequestBody ParamCopyDto params);

    @RequestMapping(method = RequestMethod.POST, value = "/flowable/process/getCopyProcessList")
    @ApiOperation(value = "查询抄送流程", notes = "查询抄送流程")
    public FlowableResponse<PageDataResult<FlowableCopyDto>> getCopyProcessList(@RequestParam(value = "pageNum") Integer pageNum,
                                                                                @RequestParam(value = "pageSize") Integer pageSize, @RequestBody ParamGetCopyListDto params);

    @RequestMapping(method = RequestMethod.GET, value = "/flowable/process/getProcessInfo")
    @ApiOperation(value = "查询流程状态", notes = "查询流程状态")
    FlowableResponse<ResponseSituationDto> getProcessInfo(@RequestParam(value = "processId") String processId);

    @RequestMapping(method = RequestMethod.POST, value = "/flowable/process/getCopyProcessDetail")
    @ApiOperation(value = "查询抄送流程细节", notes = "查询抄送流程细节")
    FlowableResponse<ResponseCopyDetailDto> getCopyProcessDetail(@RequestBody ParamCopyDetailDto params);


    /**
     * 转办流程
     */
    @RequestMapping(method = RequestMethod.POST, value = "/flowable/process/turnTask")
    @ApiOperation(value = "转办流程", notes = "待办人将流程分配给其他人")
    FlowableResponse<ResponseTurnDto> turnTask(@RequestBody ParamTurnDto params);

    /**
     * 增加任务评论
     */
    @RequestMapping(method = RequestMethod.POST, value = "/flowable/process/addTaskComment")
    @ApiOperation(value = "增加任务评论", notes = "增加任务评论")
    FlowableResponse<ResponseMsgDto> addTaskComment(@RequestBody ParamAddTaskCommentDto params);


    /**
     * 删除流程
     * <p>
     * 接口仅接收ParamDeleteDto.processIdList参数有
     */
    @RequestMapping(method = RequestMethod.POST, value = "/flowable/process/deleteProcess")
    @ApiOperation(value = "删除流程", notes = "删除流程")
    FlowableResponse<ResponseMsgDto> deleteProcess(@RequestBody ParamDeleteDto paramDeleteDto);


    /**
     * 调用网关批量上传接口
     *
     * @param file
     * @return
     */
    @RequestMapping(value = "/flowable/common/uploadDoc", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    FlowableResponse<ResponseUploadDto> uploadDoc(@RequestPart(value = "file") MultipartFile[] file) throws IOException;

    @RequestMapping(method = RequestMethod.GET, value = "/flowable/process/getVariableByProcessId")
    @ApiOperation(value = "获取待办人或者变量", notes = "获取待办人或者变量")
    FlowableResponse<ParamSetupVariableDto> getVariableByProcessId(@RequestParam(value = "processId") String processId);

    @RequestMapping(method = RequestMethod.POST, value = "/flowable/process/setupVariableByProcessId")
    @ApiOperation(value = "设置待办人或者变量", notes = "设置待办人或者变量")
    FlowableResponse<String> setupVariableByProcessId(@RequestBody ParamSetupVariableDto paramSetupVariableDto);


    @RequestMapping(method = RequestMethod.POST, value = "/flowable/process/getCopyProcessOfUser")
    @ApiOperation(value = "查询用户对某个流程的抄送信息", notes = "查询用户对某个流程的抄送信息")
    FlowableResponse<ResponseCopyUserDto> getCopyProcessOfUser(@RequestBody ParamCopyUserDto params);

    @PostMapping("/flowable/common/getAppendixInfos")
    ResponseEntity<List<FlowableAppendDto>> getAppendixInfos(@RequestBody List<String> appendixIds);

    @RequestMapping("/flowable/common/downloadDemandAppendix")
    ResponseEntity<byte[]> downloadDemandAppendix(@RequestParam(value = "appendixId") String appendixId);

    @RequestMapping(method = RequestMethod.POST, value = "/flowable/processNew/searchDealProcessList")
    @ApiOperation(value = "通过用户列表和流程类型列表查询所有待办", notes = "通过用户列表和流程类型列表查询所有待办")
    FlowableResponse<PageDataResult<ResponseSituationDto>> searchDealProcessList(@RequestParam(value = "pageNum") Integer pageNum,
                                                                                 @RequestParam(value = "pageSize") Integer pageSize,
                                                                                 @RequestBody ParamSearchDto param);

    /**
     * 查看流程实例明细--历史
     */
    @RequestMapping("/flowable/processNew/searchProcessList")
    FlowableResponse<PageDataResult<ResponseSituationDto>> searchAllOrStartProcessList(@RequestParam(value = "pageNum") Integer pageNum,
                                                                                       @RequestParam(value = "pageSize") Integer pageSize, @RequestBody ParamSearchDto params);

    /**
     * 查看流程实例明细--关联
     */
    @RequestMapping("/flowable/processNew/searchInvolveUserProcessList")
    FlowableResponse<PageDataResult<ResponseSituationDto>> searchInvolveUserProcessList(@RequestParam(value = "pageNum") Integer pageNum,
                                                                                        @RequestParam(value = "pageSize") Integer pageSize, @RequestBody ParamSearchDto params);
    /**
     * 流程查询实例接口
     *
     * @return
     */
    @RequestMapping("/flowable/process/searchProcessList")
    FlowableResponse<PageDataResult<ResponseSituationDto>> searchProcessList(@RequestParam(value = "pageNum") Integer pageNum,
                                                                             @RequestParam(value = "pageSize") Integer pageSize, @RequestBody ParamSearchDto params);

    @RequestMapping(method = RequestMethod.GET, value = "/flowable/processNew/findAssigneeByProcessDefinitionKey")
    @ApiOperation(value = "获取流程会签人", notes = "获取流程会签人")
    FlowableResponse<List<FlowableAssigneeDto>> findAssigneeByProcessDefinitionKey(@RequestParam(value = "processDefinitionKey") String processDefinitionKey, @RequestParam(value = "sysid") String sysid);

    @RequestMapping("/flowable/demand/getDemandInfo")
    FlowableResponse<FlowableDemandDto> getDemandInfo(@RequestParam(value = "processId") String processId);

    @RequestMapping("/flowable/demand/getDemandInfos")
    FlowableResponse<List<FlowableDemandDto>> getDemandInfos(@RequestBody List<String> processIds);

    @PostMapping("/flowable/process/queryCommentsByProcessIds")
    FlowableResponse<List<ResponseCommentDto>> queryCommentsByProcessIds(@RequestBody List<String> processIds);

    @PostMapping("/flowable/demand/updateEmergeLevel")
    FlowableResponse updateEmergeLevel(@RequestParam(value = "processId") String processId,
                                       @RequestParam(value = "demandEmergeLevel") String demandEmergeLevel);

    @RequestMapping(method = RequestMethod.POST, value = "/flowable/process/updateProcessTitle")
    @ApiOperation(value = "更新流程标题", notes = "更新流程标题")
    FlowableResponse updateProcessTitle(@RequestBody ParamUpdateTitleDto paramUpdateTitleDto);

    @RequestMapping(method = RequestMethod.GET, value = "/flowable/ehr/getUserInfo")
    @ApiOperation(value = "查询用户信息（OA用户信息）", notes = "查询用户信息（OA用户信息）")
    FlowableResponse<FlowableEhrEmpDto> getUserInfoByAccount(@RequestParam(value = "userId") String userId);

    @RequestMapping(method = RequestMethod.POST, value = "/flowable/process/return2SelectNode")
    @ApiOperation(value = "跳回指定接口", notes = "跳回指定接口")
    FlowableResponse<ResponseMsgDto> return2SelectNode(@RequestBody ParamRollbackDto params);

    @RequestMapping(method = RequestMethod.GET, value = "/flowable/process/getAllSourceList")
    @ApiOperation(value = "获取所有可回退节点", notes = "获取所有可回退节点")
    FlowableResponse<List<TaskDefinitionDto>> getAllSourceList(@RequestParam("taskId") String taskId);

    @RequestMapping(method = RequestMethod.POST, value = "/flowable/process/forwardByTask")
    @ApiOperation(value = "流程转发", notes = "流程转发")
    FlowableResponse<ForwardFlowableResponse> forwardFlowableByTask(@RequestBody ForwardFlowableParamDto param);


    @RequestMapping(method = RequestMethod.GET, value = "/flowable/demand/findByVcStaffLikeOrVcOriginalStaffOrDevUserId")
    @ApiOperation(value = "通过需求人、原始需求人,需求明细，同部门发起人查询流程信息", notes = "通过需求人、原始需求人，需求明细，同部门发起人查询流程信息")
    FlowableResponse<List<FlowableDemandDto>> findByVcStaffLikeOrVcOriginalStaffOrDevUserId(@RequestParam(value = "vcStaff")String vcStaff, @RequestParam(value = "vcOriginalStaff")String vcOriginalStaff, @RequestParam(value = "devUserId")String devUserId,@RequestParam(value = "sameDepartmentAccounts") List<String> sameDepartmentAccounts,@RequestParam(value = "demandDetail") String demandDetail);

    @RequestMapping(method = RequestMethod.GET, value = "/flowable/processNew/queryProcessListByCurrentAssignee")
    @ApiOperation(value = "查询当前处理人的流程id", notes = "查询当前处理人的流程id")
    FlowableResponse<List<String>> queryProcessListByCurrentAssignee(@RequestParam(value = "dealUser")String dealUser, @RequestParam(value = "processDefineKey")String processDefineKey, @RequestParam(value = "createProject")String createProject);
}
